# 
# Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
# 
# This software is licensed under the Argot Public License 
# which may be found in the file LICENSE distributed 
# with this software.
# 
# More information about this license can be found at
# http://www.einet.com.au/License
#
# The Developer of this software is Live Media Pty Ltd,
# PO Box 4591, Melbourne 3001, Australia.  The license is subject 
# to the law of Victoria, Australia, and subject to exclusive 
# jurisdiction of the Victorian courts.
#
 
#DEBUG=yes
#STDANSI=0


CC=gcc
AS=as
AR=ar
LD=ld

ifdef DEBUG
  CFLAGS=-Wall -g -std=c99 -fno-inline -DDEBUG
else
  ifdef STDANSI
      CFLAGS=-Wall -ansi -O2 -pedantic -DSTDANSI -DINLINE="inline extern"
  else
	  CFLAGS=-Wall -std=c99 -O2 -DINLINE="inline extern"
  endif
endif

TYPE_DIR = src/
UTIL_DIR = src/util/
COMMON_DIR= src/common/
META_DIR = src/meta/
NET_DIR = src/network/
DICT_DIR = src/dictionary/
MSG_DIR = src/message/

all: libargot.a TypeTest.exe

release: clean
	mkdir -p release
	mkdir -p release/src
	# copy directories and excluse SVN directories.
	tar -C src --exclude=.svn -cf - . | tar -C release/src -xf -
	mkdir -p release/test
	tar -C test --exclude=.svn -cf - . | tar -C release/test -xf -
	cp LICENSE.TXT release
	cp BUILD.TXT release
	cp README.TXT release
	cp Makefile release
	# external files required for release.
	mkdir -p release/argot
	cp ../argot/* release/argot
	mkdir -p release/bin
	cp ../../tools/argot_compiler/release/bin/ac.bat release/bin
	mkdir -p release/lib
	cp ../../tools/argot_compiler/release/lib/*.jar release/lib
	mkdir -p release/doc
	cp ../doc/ArgotProgrammersGuide.pdf release/doc
	tar -C release -cvzf ../ArgotC-1.2.0.tar.gz .


clean: 
	rm -f src/*.o
	rm -f src/util/*.o
	rm -f src/meta/*.o
	rm -f src/common/*.o
	rm -f src/dictionary/*.o
	rm -f src/message/*.o
	rm -f src/network/*.o
	rm -f test/*.o
	rm -f test/src/*.o
	rm -f test/src/data/*.o
	rm -f test/src/message/*.o
	rm -f test/src/network/*.o
	rm -f test/TypeUnitTest.exe*
	rm -f libargot.a
	rm -f TypeTest.exe


UTIL = $(UTIL_DIR)buffer.o \
	   $(UTIL_DIR)chunkbuffer.o \
	   $(UTIL_DIR)intmap.o \
	   $(UTIL_DIR)typestack.o 

META = $(META_DIR)MetaAbstract.o \
	   $(META_DIR)MetaArray.o \
	   $(META_DIR)MetaBasic.o \
	   $(META_DIR)MetaDefinition.o \
	   $(META_DIR)MetaExpression.o \
	   $(META_DIR)MetaEncoding.o \
	   $(META_DIR)MetaEnvelop.o \
	   $(META_DIR)MetaMap.o \
	   $(META_DIR)MetaMarshaller.o \
	   $(META_DIR)MetaName.o \
	   $(META_DIR)MetaReference.o \
	   $(META_DIR)MetaSequence.o \
	   $(META_DIR)MetaDefinition.o \
	   $(META_DIR)MetaIdentified.o

DICTIONARY = $(DICT_DIR)Dictionary.o \
		$(DICT_DIR)DictionaryTypes.o \
		$(DICT_DIR)TypeMapMarshaller.o

MESSAGE = $(MSG_DIR)MessageReader.o \
		$(MSG_DIR)MessageWriter.o

NETWORK = $(NET_DIR)DynamicClientTypeMap.o \
		$(NET_DIR)ProtocolTypeMap.o \
		$(NET_DIR)TypeClient.o \
		$(NET_DIR)TypeServer.o

TYPES = $(TYPE_DIR)DynamicTypeMap.o \
		$(TYPE_DIR)ReferenceTypeMap.o \
		$(TYPE_DIR)TypeCore.o \
		$(TYPE_DIR)TypeElement.o \
		$(TYPE_DIR)TypeHelper.o \
		$(TYPE_DIR)TypeInputStream.o \
		$(TYPE_DIR)TypeLibrary.o \
		$(TYPE_DIR)TypeMap.o \
		$(TYPE_DIR)TypeObject.o \
		$(TYPE_DIR)TypeOutputStream.o \
		$(TYPE_DIR)TypeReaderAuto.o \
		$(TYPE_DIR)TypeBindCommon.o \
		$(TYPE_DIR)TypeMapCore.o

COMMON =  $(COMMON_DIR)BigEndianSignedByte.o \
		$(COMMON_DIR)BigEndianSignedInteger.o \
		$(COMMON_DIR)BigEndianSignedShort.o \
		$(COMMON_DIR)BigEndianSignedLong.o \
		$(COMMON_DIR)BigEndianUnsignedByte.o \
		$(COMMON_DIR)BigEndianUnsignedInteger.o \
		$(COMMON_DIR)BigEndianUnsignedShort.o \
		$(COMMON_DIR)BigEndianUnsignedLong.o \
		$(COMMON_DIR)Empty.o \
		$(COMMON_DIR)Error.o \
		$(COMMON_DIR)U16ArrayByte.o \
		$(COMMON_DIR)U32ArrayByte.o \
		$(COMMON_DIR)U32UTF8.o \
		$(COMMON_DIR)U8Ascii.o \
		$(COMMON_DIR)U8Boolean.o

ifndef INLINE
INLINEOBJS=$(UTIL_DIR)typestackInline.o $(COMMON_DIR)EndianInline.o
else
INLINEOBJS=
endif

TEST = test/TypeTest.o

OBJ_DIR = obj

libargot.a: $(UTIL) $(COMMON) $(META) $(TYPES) $(INLINEOBJS) $(DICTIONARY) $(MESSAGE) $(NETWORK)
	$(AR) cru libargot.a  $(UTIL) $(COMMON) $(META) $(TYPES) $(INLINEOBJS) $(DICTIONARY) $(MESSAGE) $(NETWORK)

TypeTest.exe: $(TEST) libargot.a
	$(CC) -g -L . -o TypeTest.exe $(TEST) -largot

%.o: %.c
	@echo "-------------------------------------------------"
	$(CC) -c $(CFLAGS) -o $@ $<

$(INLINEOBJS):
	@echo "-------------------------------------------------"
	$(CC) -c $(CFLAGS) -DINLINE="" -o $@ $*.c
	

	
